package studio.raptor.ddal.dashboard.log.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import studio.raptor.ddal.dashboard.log.queue.interfaces.IQueueManager;
import studio.raptor.ddal.dashboard.log.service.interfaces.ILogManagerService;
import studio.raptor.ddal.dashboard.log.thread.ThreadManager;

/**
 * 类名称 LogManagerService<br>
 * 日志服务器端管理类
 * <hr>
 * 修改记录
 * <hr>
 * 1、修改人员:    修改时间:<br>
 *    修改内容:
 * <hr>
 */
@Service
public class LogManagerService implements ILogManagerService {

	private ThreadManager threadManager;

	private IQueueManager queueManager;

	@Autowired
	public LogManagerService(ThreadManager threadManager,IQueueManager queueManager){
		this.threadManager=threadManager;
		this.queueManager=queueManager;
		initQueueManage();
		startThread();
	}

	/**
	 * 队列管理器初始化
	 */
	public void initQueueManage() {
		queueManager.init();
	}

	/**
	 * 初始化日志检查文件线程
	 * 同时启动从队列获取数据线程
	 */
	public void startThread(){
		threadManager.startFrontQueueThread();
	}

	/**
	 * 停止线程
	 */
	public void stopThread(){
		threadManager.stopFrontQueueThread();
	}

	public void readObject(String queueName){
		queueManager.readObject(queueName);
	}

	public int getQueueLength(String queueName){
		return queueManager.getQueueLength(queueName);
	}

	public void writeObject(String queueName ,Object object){
		queueManager.writeObject(queueName, object);
	}

	public void setThreadManager(ThreadManager threadManager) {
		this.threadManager = threadManager;
	}

	public void setQueueManager(IQueueManager queueManager) {
		this.queueManager = queueManager;
	}
}